﻿@model List<wne.models.UserModel>
@{
    Layout = null;
}
<script>
    $(document).ready(function ()
    {
        $("#userPartial input[type=checkbox]").click(function(e)
        {
            var fieldId = $(e.target).attr("data-fieldid");
            $("#userTable td[data-fieldid=" + fieldId + "]").toggle();
        });
    });
</script>
    <div class="wfull">
        Логин
        <input type="checkbox" data-fieldid="-7" checked="checked" />
        Фамилия
        <input type="checkbox" data-fieldid="-6" checked="checked" />
        Имя
        <input type="checkbox" data-fieldid="-5" checked="checked" />
        Отчество
        <input type="checkbox" data-fieldid="-4" checked="checked" />
        Email
        <input type="checkbox" data-fieldid="-3"  checked="checked"/>
        День рождения
        <input type="checkbox" data-fieldid="-2"  checked="checked"/>
        Телефон
        <input type="checkbox" data-fieldid="-1"  checked="checked"/>
        @if (ViewBag.SelectedGroup != -1)
        {
            if (Model.FirstOrDefault() != null &&
                Model.FirstOrDefault().UserGroups.FirstOrDefault(x => x.Id == ViewBag.SelectedGroup) != null)
            {
                foreach (var fieldName in Model.FirstOrDefault().UserGroups.FirstOrDefault(x => x.Id == ViewBag.SelectedGroup).Fields)
                {
                    @fieldName.Name
                    <input type="checkbox" checked="checked" data-fieldId="@fieldName.FieldId" />
                }
            }
        }
    </div>
    <table id="userTable" class="table table-hover">
        <tr>
            <td data-fieldid="-7">Логин</td>
            <td data-fieldid="-6">Фамилия</td>
            <td data-fieldid="-5">Имя</td>
            <td data-fieldid="-4">Отчество</td>
            <td data-fieldid="-3">Email</td>
            <td data-fieldid="-2">День рождения</td>
            <td data-fieldid="-1">Телефон</td>
            @if (ViewBag.SelectedGroup != -1)
            {
                if (Model.FirstOrDefault() != null &&
                    Model.FirstOrDefault().UserGroups.FirstOrDefault(x => x.Id == ViewBag.SelectedGroup) != null)
                {
                    foreach (var fieldName in Model.FirstOrDefault().UserGroups.FirstOrDefault(x => x.Id == ViewBag.SelectedGroup).Fields)
                    {
                        <td data-fieldid="@fieldName.FieldId">@fieldName.Name</td>
                    }
                }
            }
            @*@foreach (var field in Model.FirstOrDefault().UserGroups.FirstOrDefault().Fields)
            {
                <td data-fieldId="@field.FieldId">@field.Name</td>
            }*@
    </tr>
        @if (Model != null)
        {
            foreach (var user in Model)
            {
                <tr>
                    <td data-fieldid="-7"><a href="/Admin/EditUser?id=@user.Id">@user.UserName</a></td>
                    <td data-fieldid="-6">@user.Surname</td>
                    <td data-fieldid="-5">@user.FirstName</td>
                    <td data-fieldid="-4">@user.SecondName</td>
                    <td data-fieldid="-3">@user.UserEmail</td>
                    <td data-fieldid="-2">@user.UserBd</td>
                    <td data-fieldid="-1">@user.Phone</td>
                    @if (user.UserGroups.FirstOrDefault(x => x.Id == ViewBag.SelectedGroup) != null)
                    {
                        foreach (var fieldName in user.UserGroups.FirstOrDefault(x => x.Id == ViewBag.SelectedGroup).Fields)
                        {
                            @fieldName.Name
                            <td data-fieldId="@fieldName.FieldId">@fieldName.Value</td>
                        }
                    }
                    <td><i class="icon-remove" onclick=" delUser_fromAllUsersPage($(this), @user.Id); "></i></td>
                </tr>
            }
        }
    </table>
